home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / bytecomp / bytecomp-runtime.el < prev    next >
Encoding:
Text File  |  1995-03-25  |  7.8 KB  |  208 lines

  1. ;;; -*- Mode:Emacs-Lisp -*-
  2.  
  3. ;; Runtime support for the new optimizing byte compiler.  
  4. ;; By Jamie Zawinski <jwz@lucid.com>.
  5. ;; Last Modified: 17-mar-94.
  6. ;;
  7. ;; The code in this file should always be loaded, because it defines things 
  8. ;; like "defsubst" which should work interpreted as well.  The code in 
  9. ;; bytecomp.el and byte-optimize.el can be loaded as needed.
  10. ;;
  11. ;; This should be loaded by loadup.el or startup.el.  If you can't modify
  12. ;; those files, load this from your .emacs file.  But if you are using
  13. ;; emacs18, this file must be loaded before any .elc files which were
  14. ;; generated by the new compiler without emacs18 compatibility turned on.
  15. ;; If this file is loaded, certain emacs19 binaries will run in emacs18.
  16. ;; Meditate on the meanings of byte-compile-generate-emacs19-bytecodes and
  17. ;; byte-compile-emacs18-compatibility.
  18.  
  19.  
  20. ;; Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
  21.  
  22. ;; This file is part of XEmacs.
  23.  
  24. ;; XEmacs is free software; you can redistribute it and/or modify it
  25. ;; under the terms of the GNU General Public License as published by
  26. ;; the Free Software Foundation; either version 2, or (at your option)
  27. ;; any later version.
  28.  
  29. ;; XEmacs is distributed in the hope that it will be useful, but
  30. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  31. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  32. ;; General Public License for more details.
  33.  
  34. ;; You should have received a copy of the GNU General Public License
  35. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  36. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  37.  
  38.  
  39. ;; emacs-18 compatibility.
  40.  
  41. (if (fboundp 'make-byte-code)
  42.     nil
  43.   ;;
  44.   ;; To avoid compiler bootstrapping problems, this temporary uncompiled
  45.   ;; make-byte-code is needed to load the compiled one.  Ignore the warnings.
  46.   (fset 'make-byte-code
  47.     '(lambda (arglist bytestring constants stackdepth doc)
  48.        (list 'lambda arglist doc
  49.          (list 'byte-code bytestring constants stackdepth))))
  50.   ;;
  51.   ;; Now get a compiled version.
  52.   (defun make-byte-code (arglist bytestring constants stackdepth
  53.                  &optional doc &rest interactive)
  54.     "For compatibility with Emacs19 ``.elc'' files."
  55.     (nconc (list 'lambda arglist)
  56.        ;; #### Removed the (stringp doc) for speed.  Because the V19
  57.        ;;    make-byte-code depends on the args being correct, it won't
  58.        ;;    help to make a smarter version for V18 alone.
  59.        ;;    Btw, it should have been (or (stringp doc) (natnump doc)).  
  60.        (if doc (list doc))
  61.        (if interactive
  62.            (list (cons 'interactive (if (car interactive) interactive))))
  63.        (list (list 'byte-code bytestring constants stackdepth)))))
  64.  
  65.  
  66. ;;; interface to selectively inlining functions.
  67. ;;; This only happens when source-code optimization is turned on.
  68.  
  69. ;; Redefined in byte-optimize.el.
  70. (fset 'inline 'progn)
  71. (put 'inline 'lisp-indent-hook 0)
  72.  
  73.  
  74. ;;; Interface to inline functions.
  75.  
  76. (defmacro proclaim-inline (&rest fns)
  77.   "Cause the named functions to be open-coded when called from compiled code.
  78. They will only be compiled open-coded when byte-optimize is true."
  79.   (cons 'eval-and-compile
  80.     (apply
  81.      'nconc
  82.      (mapcar
  83.       '(lambda (x)
  84.          (` ((or (memq (get '(, x) 'byte-optimizer)
  85.                '(nil byte-compile-inline-expand))
  86.              (error
  87.               "%s already has a byte-optimizer, can't make it inline"
  88.               '(, x)))
  89.          (put '(, x) 'byte-optimizer 'byte-compile-inline-expand))))
  90.       fns))))
  91.  
  92.  
  93. (defmacro proclaim-notinline (&rest fns)
  94.   "Cause the named functions to no longer be open-coded."
  95.   (cons 'eval-and-compile
  96.     (apply
  97.      'nconc
  98.      (mapcar
  99.       '(lambda (x)
  100.          (` ((if (eq (get '(, x) 'byte-optimizer)
  101.              'byte-compile-inline-expand)
  102.              (put '(, x) 'byte-optimizer nil)))))
  103.       fns))))
  104.  
  105. ;; This has a special byte-hunk-handler in bytecomp.el.
  106. (defmacro defsubst (name arglist &rest body)
  107.   "Define an inline function.  The syntax is just like that of `defun'."
  108.   (or (memq (get name 'byte-optimizer)
  109.         '(nil byte-compile-inline-expand))
  110.       (error "`%s' is a primitive" name))
  111.   (list 'prog1
  112.     (cons 'defun (cons name (cons arglist body)))
  113.     (list 'proclaim-inline name)))
  114.  
  115. (defun make-obsolete (fn new)
  116.   "Make the byte-compiler warn that FUNCTION is obsolete.
  117. The warning will say that NEW should be used instead.
  118. If NEW is a string, that is the `use instead' message."
  119.   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
  120.   (let ((handler (get fn 'byte-compile)))
  121.     (if (eq 'byte-compile-obsolete handler)
  122.     (setcar (get fn 'byte-obsolete-info) new)
  123.       (put fn 'byte-obsolete-info (cons new handler))
  124.       (put fn 'byte-compile 'byte-compile-obsolete)))
  125.   fn)
  126.  
  127. (defun make-obsolete-variable (var new)
  128.   "Make the byte-compiler warn that VARIABLE is obsolete,
  129. and NEW should be used instead.  If NEW is a string, then that is the
  130. `use instead' message."
  131.   (interactive
  132.    (list
  133.     (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
  134.       (if (equal str "") (error ""))
  135.       (intern str))
  136.     (car (read-from-string (read-string "Obsoletion replacement: ")))))
  137.   (put var 'byte-obsolete-variable new)
  138.   var)
  139.  
  140. (put 'dont-compile 'lisp-indent-hook 0)
  141. (defmacro dont-compile (&rest body)
  142.   "Like `progn', but the body always runs interpreted (not compiled).
  143. If you think you need this, you're probably making a mistake somewhere."
  144.   (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
  145.  
  146.  
  147. ;;; interface to evaluating things at compile time and/or load time
  148. ;;; these macro must come after any uses of them in this file, as their
  149. ;;; definition in the file overrides the magic definitions on the
  150. ;;; byte-compile-macro-environment.
  151.  
  152. (put 'eval-when-compile 'lisp-indent-hook 0)
  153. (defmacro eval-when-compile (&rest body)
  154.   "Like `progn', but evaluates the body at compile time.
  155. The result of the body appears to the compiler as a quoted constant."
  156.   ;; Not necessary because we have it in b-c-initial-macro-environment
  157.   ;; (list 'quote (eval (cons 'progn body)))
  158.   (cons 'progn body))
  159.  
  160. (put 'eval-and-compile 'lisp-indent-hook 0)
  161. (defmacro eval-and-compile (&rest body)
  162.   "Like `progn', but evaluates the body at compile time and at load time."
  163.   ;; Remember, it's magic.
  164.   (cons 'progn body))
  165.  
  166.  
  167. ;;; Interface to file-local byte-compiler parameters.
  168. ;;; Redefined in bytecomp.el.
  169.  
  170. (put 'byte-compiler-options 'lisp-indent-hook 0)
  171. (defmacro byte-compiler-options (&rest args)
  172.   "Set some compilation-parameters for this file.  
  173. This will affect only the file in which it appears; this does nothing when
  174. evaluated, and when loaded from a .el file.
  175.  
  176. Each argument to this macro must be a list of a key and a value.
  177.  
  178.   Keys:          Values:        Corresponding variable:
  179.  
  180.   verbose      t, nil        byte-compile-verbose
  181.   optimize      t, nil, source, byte    byte-optimize
  182.   warnings      list of warnings    byte-compile-warnings
  183.   file-format      emacs18, emacs19    byte-compile-emacs18-compatibility
  184.   new-bytecodes      t, nil        byte-compile-generate-emacs19-bytecodes
  185.  
  186. The value specificed with the `warnings' option must be a list, containing
  187. some subset of the following flags:
  188.  
  189.   free-vars    references to variables not in the current lexical scope.
  190.   unused-vars    references to non-global variables bound but not referenced.
  191.   unresolved    calls to unknown functions.
  192.   callargs    lambda calls with args that don't match the definition.
  193.   redefine    function cell redefined from a macro to a lambda or vice
  194.         versa, or redefined to take a different number of arguments.
  195.  
  196. If the first element if the list is `+' or `-' then the specified elements 
  197. are added to or removed from the current set of warnings, instead of the
  198. entire set of warnings being overwritten.
  199.  
  200. For example, something like this might appear at the top of a source file:
  201.  
  202.     (byte-compiler-options
  203.       (optimize t)
  204.       (warnings (- callargs))        ; Don't warn about arglist mismatch
  205.       (warnings (+ unused-vars))    ; Do warn about unused bindings
  206.       (file-format emacs19))"
  207.   nil)
  208.